/*
 * Copyright 2016 Wealth Inc. All rights reserved.
 */
 package com.wealth.page.service.impl;

import java.util.Collection;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Sort;
import org.springframework.data.domain.Sort.Direction;
import org.springframework.data.jpa.domain.Specification;
import org.springframework.stereotype.Component;

import com.wealth.page.entity.FloorItem;
import com.wealth.page.repository.FloorItemDao;
import com.wealth.page.service.IFloorItemService;
import com.wealth.system.service.ShiroUser;

import iaas.enums.StatusEnum;
import iaas.persistence.DynamicSpecifications;
import iaas.persistence.SearchFilter;
import iaas.persistence.SearchFilter.Operator;
import iaas.service.impl.BaseServiceImpl;
import iaas.utils.ResultObject;
import iaas.web.JqGridRequest;

/**
 * @author chan
 */
@Component
public class FloorItemServiceImpl extends BaseServiceImpl<FloorItem> implements IFloorItemService{

	@Autowired
	private FloorItemDao floorItemDao;

	public Page<FloorItem> getFloorItem(Long corpid, Long floorId , JqGridRequest request) throws Exception{
		//创建分页请求.
		int pageNumber = request.getPage();
		int pageSize = request.getRows();
		String sortType = StringUtils.isEmpty(request.getSidx())?"id":request.getSidx();
		String sortDirection = StringUtils.isEmpty(request.getSord())?"desc":request.getSord();
		Direction direction = sortDirection.equals("desc")?Direction.DESC:Direction.ASC;
		Sort sort = new Sort(direction, sortType);
		PageRequest pageRequest = new PageRequest(pageNumber - 1, pageSize, sort);

		//创建动态查询条件组合.
		Collection<SearchFilter> filters = SearchFilter.parse(request);
		filters.add(new SearchFilter("status", Operator.NE, StatusEnum.DELETE.getValue()));
		filters.add(new SearchFilter("floor.id", Operator.EQ, floorId));
		Specification<FloorItem> spec = DynamicSpecifications.bySearchFilter(filters, FloorItem.class);
		return floorItemDao.findAll(spec, pageRequest);
	}

//	@Override
//	public List<FloorItem> findByFloorId(Long floorId) {
//		return floorItemDao.findByFloorId(floorId);
//	}
//
//	@Override
//	public void updateStatus(Long floorId) {
//		FloorItem floorItem= floorItemDao.findOne(floorId);
//		floorItem.setStatus(0);
//		floorItemDao.save(floorItem);
//		
//	}
//
//	@Override
//	public List<FloorItem> getFloorItemByCorpIdAndStatus(Long corpid, int value) {
//		return floorItemDao.getFloorItemByCorpIdAndStatus(corpid,value);
//	}
}
